package com.just.bz_back.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.just.bz_back.dao.RepairAdminDescriptionMapper;
import com.just.bz_back.dao.RepairUserDescriptionMapper;
import com.just.bz_back.model.RepairAdminDescription;
import com.just.bz_back.model.RepairAdminDescriptionExample;
import com.just.bz_back.model.RepairUserDescription;
import com.just.bz_back.model.RepairUserDescriptionExample;
import com.just.bz_back.service.DescriptionService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author : baibaiwucahng
 * @date : 2019/9/6  22:21
 */
@Service
public class DescriptionServiceImpl implements DescriptionService {

    @Resource
    private RepairUserDescriptionMapper repairUserDescriptionMapper;
    @Resource
    private RepairAdminDescriptionMapper repairAdminDescriptionMapper;
    @Override
    public PageInfo<RepairUserDescription> getDescriptionList(RepairUserDescription repairUserDescription) {
        PageHelper.startPage(repairUserDescription.getPage().getPageNum(),repairUserDescription.getPage().getPageSize());
        RepairUserDescriptionExample example=new RepairUserDescriptionExample();
        if (repairUserDescription.getTypeId()!=null) {
            example.createCriteria().andTypeIdEqualTo(repairUserDescription.getTypeId());
        }
        List<RepairUserDescription> descriptions=repairUserDescriptionMapper.selectByExampleWithBLOBs(example);
        PageInfo<RepairUserDescription> pageInfo=new PageInfo<>(descriptions);
        return pageInfo;


    }

    @Override
    public int updateDecription(RepairUserDescription repairUserDescription) {
        RepairUserDescriptionExample example=new RepairUserDescriptionExample();
        example.createCriteria().andIdEqualTo(repairUserDescription.getId());
        repairUserDescriptionMapper.updateByExampleSelective(repairUserDescription,example);
        return 0;
    }

    @Override
    public int insertAdmin(RepairAdminDescription repairAdminDescription) {
        repairAdminDescriptionMapper.insertSelective(repairAdminDescription);
        return 0;
    }

    @Override
    public int insertUser(RepairUserDescription repairUserDescription) {
        repairUserDescriptionMapper.insertSelective(repairUserDescription);
        return 0;
    }

    @Override
    public List<RepairAdminDescription> listAdmin(RepairAdminDescription repairAdminDescription) {
        RepairAdminDescriptionExample example=new RepairAdminDescriptionExample();
        example.createCriteria().andRepairUserDescriptionIdEqualTo(repairAdminDescription.getId());
        return repairAdminDescriptionMapper.selectByExampleWithBLOBs(example);
    }

    @Override
    public int updateAdmin(RepairAdminDescription repairAdminDescription) {
        RepairAdminDescriptionExample example=new RepairAdminDescriptionExample();
        example.createCriteria().andIdEqualTo(repairAdminDescription.getId());
        repairAdminDescriptionMapper.updateByExampleSelective(repairAdminDescription,example);
        return 0;
    }
}
